package net.area80.composer.form
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public class CheckboxComposer extends FormComposer
	{
		private var skin:MovieClip;
		
		public function CheckboxComposer(skin:MovieClip)
		{
			this.skin = skin;
			skin.buttonMode = true;
			skin.gotoAndStop(1);
			skin.addEventListener(MouseEvent.CLICK, toggleHandler);
			super(skin);
		}
		private function toggleHandler (e:MouseEvent):void {
			if(skin.currentFrame==1) {
				skin.gotoAndStop(2);
			} else {
				skin.gotoAndStop(1);
			}
			dispatchEvent(new Event(Event.CHANGE));
		}
		
		public override function get value ():* {
			return checked;
		}
		public function get checked ():Boolean {
			return (skin.currentFrame==2);
		}
		public function set checked (b:Boolean):void {
			skin.gotoAndStop(((b) ? 2 : 1));
		}
		
	}
}